            
class WingController {
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only
    // accept POST requests
    def allowedMethods = [delete:'POST',
                          save:'POST',
                          update:'POST']

    def list = {
        if(!params.max)params.max = 10
        [ wingList: Wing.list( params ) ]
    }

    def show = {
        [ wing : Wing.get( params.id ) ]
    }

    def delete = {
        def wing = Wing.get( params.id )
        if(wing) {
            wing.delete()
            flash.message = "Wing ${params.id} deleted."
            redirect(action:list)
        }
        else {
            flash.message = "Wing not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def wing = Wing.get( params.id )

        if(!wing) {
                flash.message = "Wing not found with id ${params.id}"
                redirect(action:list)
        }
        else {
            return [ wing : wing ]
        }
    }

    def update = {
        def wing = Wing.get( params.id )
        if(wing) {
             wing.properties = params
            if(wing.save()) {
                redirect(action:show,id:wing.id)
            }
            else {
                render(view:'edit',model:[wing:wing])
            }
        }
        else {
            flash.message = "Wing not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def wing = new Wing()
        wing.properties = params
        return ['wing':wing]
    }

    def save = {
        def wing = new Wing()
        wing.properties = params
        if(wing.save()) {
            redirect(action:show,id:wing.id)
        }
        else {
            render(view:'create',model:[wing:wing])
        }
    }

}